package poker;

import java.util.LinkedList;

/**
 * The intelligence of player p1.
 *
 * @author Antti M. Harittu
 */
public class Computer {

    /** Player p1's hand */
    static LinkedList<Card> k;

    /**
     * If the hand contains no combinations, the smallest card is replaced. A
     * card can be replaced two times each round.
     * 
     * @return
     */
    public static int think() {
        int count = 0;

        System.out.println("-----------------------------------");
        Poker.p1.printAction();

        for (int i = 0; i < 2; i++) {
            k = Poker.p1.getHand();
            int[] win = Hands.winningHand(k);
            if (win[0] == 7) {
                changeLowest();
                count++;
                Poker.p1.printAction();
            }
        }
        return count;
    } // end think

    /** This method changes the lowest card in the hand. */
    public static void changeLowest() {
        int i = 0;
        for (int j = 0; j < 5; j++) {
            if (k.get(j).getR() < k.get(i).getR()) {
                i = j;
            }
        }
        Poker.p1.setCard(i);
    } // end changeLowest
} // end class Computer